package com.tanhua.server.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.tanhua.model.mongo.Report;
import com.tanhua.model.vo.TestQuestionsvo;
import com.tanhua.server.service.TestSoulService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/testSoul")
public class TestSoulController {

    @Autowired
    private TestSoulService testSoulService;

    /**
     * 测灵魂-问卷列表（学生实战）
     * @return
     */
    @GetMapping
    public ResponseEntity testsoul(){
        //调用service执行业务
        return ResponseEntity.ok(testSoulService.testsoul());
    }

    @PostMapping
    public ResponseEntity testSoulTijiao(@RequestBody JSONObject jsonObject){
        JSONArray answers = jsonObject.getJSONArray("answers");//作答
        List<JSONObject> list = new ArrayList<>();
        for (int i = 0; i < answers.size(); i++) {
            JSONObject answer = answers.getJSONObject(i);
            list.add(answer);
        }
        //调用service判断业务
        testSoulService.tiJiaoWenJuan(list);
        return ResponseEntity.ok(null);
    }

    @GetMapping("/report/{id}")
    public ResponseEntity ChaXun(@PathVariable("id") String id){
        //调用service操作业务
        Report report = testSoulService.ChaXun(id);
        return ResponseEntity.ok(report);
    }
}
